<?php

namespace app\admin\model\dealer;

use think\Model;
use traits\model\SoftDelete;

class DealerCompany extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'dealer_company';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];
    

    







    public function dealer()
    {
        return $this->belongsTo('app\admin\model\dealer\Dealer', 'dealer_id', 'id', ['name as dealer_name'], 'LEFT')->setEagerlyType(0);
    }


    public function company()
    {
        return $this->belongsTo('app\admin\model\Company', 'company_id', 'id', ['name as company_name'], 'LEFT')->setEagerlyType(0);
    }

    /**
     * 获取经销商下企业id
     */
    public function getCompanyIds($dealer_id){
        return $this->where(array('dealer_id'=>$dealer_id))->value('company_id');
    }
}
